package com.monitor.service.impl;

import com.monitor.entity.ErpSystemMessage;
import com.monitor.dao.ErpSystemMessageMapper;
import com.monitor.service.ErpSystemMessageService;
import com.monitor.util.Result;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;

import java.util.Date;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 消息表 服务实现类
 * </p>
 *
 * @author 
 * @since 2018-11-19
 */
@Service
@Transactional
public class ErpSystemMessageServiceImpl extends ServiceImpl<ErpSystemMessageMapper, ErpSystemMessage> implements ErpSystemMessageService {
	@Resource
	private ErpSystemMessageMapper erpSystemMessageMapper;
	
	@Override
	public Result<List<ErpSystemMessage>> getList(int userId) {
		// TODO Auto-generated method stub
		List<ErpSystemMessage> list=erpSystemMessageMapper.selectList(new EntityWrapper<ErpSystemMessage>().ne("message_type", "普通消息").and().eq("send_cust_id", userId).or().eq("receive_cust_id", userId).orderBy("id", false));
		return new Result<List<ErpSystemMessage>>(list, list.size());
	}

	@Override
	public Result<Integer> addMessage(ErpSystemMessage message) {
		// TODO Auto-generated method stub
		try {
			message.setCreateDt(new Date());
			message.setSendFlag("未读");
			int count=erpSystemMessageMapper.insert(message);
			return new Result<Integer>(count, 1);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			return new Result<>(1, e.getMessage());
		}
	}
	
}
